<?php
namespace Adminx\Controller;

class FeedbackController extends AdminController {

	public $modelID=8;

	public function index(){
		$map['model']=$this->modelID;
		$cateArr = M('Category')->where($map)->getField('id,name');
		$cid = I('cid');
		$keyword  = I('keyword');

		if($cid!='' && $cid!=0){
			$map['cid'] = $cid;
		}

		if($keyword!=''){
			$map['title'] = array('like', '%'.$name.'%');
		}		


		$obj = M('Feedback');
		$count = $obj->where($map)->count();
		import("Common.ORG.Page");
		$page = new \Page($count, 15);
		$show = $page->show();
		$list = $obj->where($map)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();

		unset($map);
		$map['model']=$modelID;
		$cate = M('Category')->field("id,name,fid,path")->where($map)->order('path')->select();
		foreach ($cate as $key => $value) {
			$count = count(explode('-', $value['path'])) - 3;
			$cate[$key]['count'] = $count;
		}

		$this->assign('list', $list);
		$this->assign('cateArr', $cateArr);
		$this->assign('page', $show);
		$this->assign('cate', $cate);
		$this->assign('cid', $cid);
		$this->assign('keyword', $keyword);
		$this->display();
	}

	public function reply(){
		if($_POST){//如果是post
			$data['reply'] = I('post.reply');
			$data['open'] = I('post.open');
			$id = I('post.id');
			
			if ($id=='' || !is_numeric($id)) {
				$this->error('参数错误');
			}
			if ($data['reply']=='') {
				$this->error('请输入回复内容');
			}

			if ($data['open']==0) {
				$data['open'] = 0;
			}
			$map['id'] = $id;
			$list = M('Feedback')->where($map)->save($data);
			if ($list) {
				$this->success('操作成功',U('Feedback/index'));
			}else{
				$this->error('操作失败');
			}
		}else{
			$id = (int) $_GET['id'];

			if (!isset ($id)) {
				$this->error('参数错误');
			}
			$obj = M('Feedback');
			$list = $obj->where("id=$id")->find();

			if (!$list) {
				$this->error('信息不存在');
			} else {
				unset($map);
				$map['id']=$list['cid'];
				$list['cateName']=M('Category')->where($map)->getField('name');
				$this->assign('list', $list);
				$this->display();
			}
		}			
	}

	public function del(){	
		$this->all_del('Feedback','reload');
    }
}
?>